package com.gitee.situation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.situation.manager.SituationManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gitee.situation.service.IForeignStatisticsDataService;
import com.gitee.situation.mapper.ForeignStatisticsDataMapper;
import com.gitee.situation.entity.ForeignStatisticsData;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;


/**
 * ForeignStatisticsData 实现层
 *
 * @Author wq
 * @Date 2021-04-06
 **/
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class ForeignStatisticsDataServiceImpl extends ServiceImpl<ForeignStatisticsDataMapper, ForeignStatisticsData> implements IForeignStatisticsDataService {
    @Resource
    private SituationManager situationManager;

    @Override
    public void acquire() {
        baseMapper.deleteForeignData();
        ForeignStatisticsData foreignStatisticsData = situationManager.acquireForeignData();
        if (Objects.nonNull(foreignStatisticsData)) {
            baseMapper.insert(foreignStatisticsData);
        }
    }

    @Override
    public List<ForeignStatisticsData> listForeignData() {
        acquire();
        return baseMapper.selectList(null);
    }
}